/* eslint-disable camelcase */
import { Token } from '@/types/data'
import { LoginAction } from '@/types/store'
import { getToken } from '@/utils/storage'

// 从localstorage中获取token(token持久化)
const initialState: Token = getToken()

const login = (state: Token = initialState, action: LoginAction) => {
  if (action.type === 'login/token') {
    return action.payload
  } else if (action.type === 'login/logout') {
    return initialState
  }
  return state
}

export default login
